package pl.edu.agh.gp.common;

import org.jgap.InvalidConfigurationException;
import org.jgap.gp.CommandGene;
import org.jgap.gp.impl.GPConfiguration;
import org.jgap.gp.impl.GPGenotype;
import org.jgap.gp.terminal.Variable;
import pl.edu.agh.types.VariableType;

import java.util.HashMap;
import java.util.Map;

import static org.jgap.gp.CommandGene.BooleanClass;
import static org.jgap.gp.CommandGene.DoubleClass;
import static pl.edu.agh.types.VariableType.*;
import static pl.edu.agh.types.VariableType.PRICES;

public class GenotypeProvider {
    protected Variable openPrice;
    protected Variable highPrice;
    protected Variable lowPrice;
    protected Variable closePrice;
    protected Variable prices;
    protected Variable volume;

    public Map<VariableType, Variable> getVariables() {
        Map<VariableType, Variable> variables = new HashMap<VariableType, Variable>();
        variables.put(OPEN, openPrice);
        variables.put(HIGH, highPrice);
        variables.put(LOW, lowPrice);
        variables.put(CLOSE, closePrice);
        variables.put(PRICES, prices);
        variables.put(VOLUME, volume);
        return variables;
    }

    protected GPGenotype getGenotype(CommandGene[] partialNodeSet, GPConfiguration conf, int maxNodes) throws InvalidConfigurationException {
        Class[] types = {
                BooleanClass, DoubleClass
        };
        Class[][] argTypes = {
                {}, {}
        };

        CommandGene[][] nodeSets = {partialNodeSet, partialNodeSet};
        return GPGenotype.randomInitialGenotype(conf, types, argTypes, nodeSets, maxNodes, true);
    }
}